package org.example;

public class Main {
    public static void main(String[] args) {
        // 创建工厂
        FruitFactory factory = new FruitFactory();
        
        // 使用工厂创建不同的水果
        Fruit apple = factory.createFruit("apple");
        Fruit banana = factory.createFruit("banana");
        Fruit orange = factory.createFruit("orange");
        
        // 调用水果的方法
        System.out.println("创建的水果分别是：");
        apple.showName();
        banana.showName();
        orange.showName();
        
        // 测试错误的类型
        try {
            factory.createFruit("grape");
        } catch (IllegalArgumentException e) {
            System.out.println("\n错误信息:" + e.getMessage());
        }
    }
}